//
//  TPPicker_base.m
//  TPPickerDemo
//
//  Created by 谭鹏 on 2017/8/5.
//  Copyright © 2017年 谭鹏. All rights reserved.
//

#import "TPPicker_base.h"

@implementation TPPicker_base

- (instancetype)init
{
    self = [super initWithFrame:UIScreen.mainScreen.bounds];
    if (self) {
        self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.3];
        
        _mainView = [UIView new];
        _mainView.backgroundColor = [UIColor whiteColor];
        _headerContainer = [UIView new];
        _label = [UILabel labelWithText:@"提示" font:[UIFont systemFontOfSize:17]];
        
        _cancelBtn = [UIButton new];
        
        [_cancelBtn setImage:[UIImage imageNamed:@"TPPicker_cancel"] forState:UIControlStateNormal];
        _okBtn = [UIButton new];
        [_okBtn setImage:[UIImage imageNamed:@"TPPicker_ok"] forState:UIControlStateNormal];
        _contentContainer = [UIView new];
        
        [_headerContainer addSubviews:@[_label,_cancelBtn,_okBtn]];
        [_mainView addSubviews:@[_headerContainer,_contentContainer]];
        [self addSubview:_mainView];
        
        //        [self mas_makeConstraints:^(MASConstraintMaker *make) {
        //            make.size.mas_equalTo(UIScreen.mainScreen.bounds.size);
        //        }];
        [_mainView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.bottom.right.mas_equalTo(self);
            
        }];
        [_headerContainer mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.right.mas_equalTo(_mainView);
            make.height.mas_equalTo(40);
        }];
        [_cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.bottom.mas_equalTo(_headerContainer);
            make.width.mas_equalTo(80);
        }];
        [_okBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.top.bottom.mas_equalTo(_headerContainer);
            make.width.mas_equalTo(80);
        }];
        [_label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.mas_equalTo(_headerContainer);
        }];
        [_contentContainer mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(_headerContainer.mas_bottom);
            make.left.right.bottom.mas_equalTo(_mainView);
        }];
        
        
        [_cancelBtn addTarget:self action:@selector(tapCancelBtn:) forControlEvents:UIControlEventTouchUpInside];
        //            [_okBtn addTarget:self action:@selector(dismmiss) forControlEvents:UIControlEventTouchUpInside];
    }
    return self;
}

- (void)show{
    
    [UIApplication.sharedApplication.keyWindow addSubview:self];
    
}
- (void)dismmiss{
    
    [self removeFromSuperview];
}


#pragma mark - action
-(void)tapCancelBtn:(UIButton *)btn{
    [self dismmiss];
}
@end
